package cn.com.cpic.insurance.rulecheck.core.expression;

import cn.com.cpic.insurance.rulecheck.core.Context;

public abstract class LogicalExpression extends BinaryExpression<Boolean, Boolean> {
	private static final long serialVersionUID = -1446248941671834572L;
	
	private final LogicalOperator operator;

	public LogicalExpression(Expression<Boolean> lhs, Expression<Boolean> rhs, LogicalOperator operator) {
		super(lhs, rhs);
		this.operator = operator;
	}

	@Override
	protected final Boolean operate(Context context, Boolean lValue, Boolean rValue, boolean typeMismatch) {
		switch (operator) {
		case AND:
			return lValue && rValue;
		case OR:
			return lValue || rValue;
		default:
			throw new IllegalArgumentException("不支持的操作符：" + operator);
		}
	}

	@Override
	protected final boolean canOperateWhenTypeMismatch(Context context, Boolean lValue, Boolean rValue) {
		return false;
	}
}
